package com.bishe.tax.controller.sys;

import java.util.List;

import com.bishe.tax.entity.LedgerArticle;
import com.bishe.tax.service.LedgerArticleService;
import com.bishe.tax.utils.AjaxResult;
import com.bishe.tax.utils.TableDataInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import groovy.util.logging.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 账薄归档 信息操作处理
 *
 * @author ruoyi
 * @date 2019-06-23
 */
@Controller
@RequestMapping("/system/article")
public class LedgerArticleController {
    private String prefix = "ledgerArticle";

    @Autowired
    private LedgerArticleService articleService;

    @GetMapping("list")
    public String article() {
        return prefix + "/list";
    }

    /**
     * 查询账薄归档列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LedgerArticle article,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<LedgerArticle> list = articleService.selectArticleList(article);
        return TableDataInfo.returnDataTable(new PageInfo<>(list).getTotal(), list);
    }


    /**
     * 新增账薄归档
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存账薄归档
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LedgerArticle article) {
        return AjaxResult.success(articleService.insertArticle(article));
    }

    /**
     * 修改账薄归档
     */
    @GetMapping("/edit/{laId}")
    public String edit(@PathVariable("laId") Integer laId, ModelMap mmap) {
        LedgerArticle article = articleService.selectArticleById(laId);
        mmap.put("article", article);
        return prefix + "/edit";
    }

    /**
     * 修改保存账薄归档
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LedgerArticle article) {
        return AjaxResult.success(articleService.updateArticle(article));
    }

    /**
     * 删除账薄归档
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(articleService.deleteArticleByIds(ids));
    }

}
